<!DOCTYPE html>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<script>
  var service_url = 'https://www.googleapis.com/freebase/v1-sandbox/mqlread';
  var query = [{'id': null,'name': null,'type': '/location/country'}];
  var params = {
    'cursor': '',
    'lang': '/lang/en',
    'query': JSON.stringify(query)
  }
  function fetchResults(query, params) {
    $.getJSON(service_url + '?callback=?', params, function(response) {
      $.each(response.result, function(i, topic) {
        $('<div>', {text:topic['name']}).appendTo(document.body);
      });
      params['cursor'] = response['cursor'];
      if (params['cursor'] != false) fetchResults(query, params);
    });
  }
  fetchResults(query, params);
</script>
</body>
</html>
